package com.luych.toolbox.data.service.entity;

import com.luych.toolbox.common.enums.DataCompareHistoryTableLevel;
import com.luych.toolbox.common.service.base.BaseEntity;

import javax.persistence.*;
import java.util.Arrays;
import java.util.List;

@Entity
@Table(name = "data_compare_history_table")
public class DataCompareHistoryTable extends BaseEntity {

    @Column(name = "data_compare_history_id")
    private String dataCompareHistoryId;
    @Column(name = "table_one")
    private String tableOne;
    @Column(name = "table_two")
    private String tableTwo;
    @Column(name = "comment_one")
    private String commentOne;
    @Column(name = "comment_two")
    private String commentTwo;
    @Column(name = "primary_key_one")
    private String primaryKeyOne;
    @Column(name = "primary_key_two")
    private String primaryKeyTwo;
    @Column(name = "level")
    @Enumerated(EnumType.STRING)
    private DataCompareHistoryTableLevel level;
    @Column(name = "difference")
    private String difference;
    @Column(name = "one_to_two")
    private String oneToTwo;
    @Column(name = "two_to_one")
    private String twoToOne;
    @Column(name = "one_to_two_lower")
    private String oneToTwoLower;
    @Column(name = "two_to_one_lower")
    private String twoToOneLower;
    @Column(name = "one_to_two_upper")
    private String oneToTwoUpper;
    @Column(name = "two_to_one_upper")
    private String twoToOneUpper;

    public String getDataCompareHistoryId() {
        return dataCompareHistoryId;
    }

    public void setDataCompareHistoryId(String dataCompareHistoryId) {
        this.dataCompareHistoryId = dataCompareHistoryId;
    }

    public String getTableOne() {
        return tableOne;
    }

    public void setTableOne(String tableOne) {
        this.tableOne = tableOne;
    }

    public String getTableTwo() {
        return tableTwo;
    }

    public void setTableTwo(String tableTwo) {
        this.tableTwo = tableTwo;
    }

    public String getCommentOne() {
        return commentOne;
    }

    public void setCommentOne(String commentOne) {
        this.commentOne = commentOne;
    }

    public String getCommentTwo() {
        return commentTwo;
    }

    public void setCommentTwo(String commentTwo) {
        this.commentTwo = commentTwo;
    }

    public String getPrimaryKeyOne() {
        return primaryKeyOne;
    }

    public List<String> getPrimaryKeyListOne() {
        return primaryKeyOne == null ? null : Arrays.asList(primaryKeyOne.split(","));
    }

    public void setPrimaryKeyOne(String primaryKeyOne) {
        this.primaryKeyOne = primaryKeyOne;
    }

    public void setPrimaryKeyListOne(List<String> primaryKeyListOne) {
        this.primaryKeyOne = String.join(",", primaryKeyListOne);
    }

    public String getPrimaryKeyTwo() {
        return primaryKeyTwo;
    }

    public List<String> getPrimaryKeyListTwo() {
        return primaryKeyTwo == null ? null : Arrays.asList(primaryKeyTwo.split(","));
    }

    public void setPrimaryKeyTwo(String primaryKeyTwo) {
        this.primaryKeyTwo = primaryKeyTwo;
    }

    public void setPrimaryKeyListTwo(List<String> primaryKeyTwo) {
        this.primaryKeyTwo = String.join(",", primaryKeyTwo);
    }

    public DataCompareHistoryTableLevel getLevel() {
        return level;
    }

    public void setLevel(DataCompareHistoryTableLevel level) {
        this.level = level;
    }

    public String getDifference() {
        return difference;
    }

    public void setDifference(String difference) {
        this.difference = difference;
    }

    public void addDifference(String difference) {
        if (this.difference == null) {
            this.difference = "";
        }
        this.difference += difference + "\r\n";
    }

    public String getOneToTwo() {
        return oneToTwo;
    }

    public void setOneToTwo(String oneToTwo) {
        this.oneToTwo = oneToTwo;
    }

    public String getTwoToOne() {
        return twoToOne;
    }

    public void setTwoToOne(String twoToOne) {
        this.twoToOne = twoToOne;
    }

    public String getOneToTwoLower() {
        return oneToTwoLower;
    }

    public void setOneToTwoLower(String oneToTwoLower) {
        this.oneToTwoLower = oneToTwoLower;
    }

    public String getTwoToOneLower() {
        return twoToOneLower;
    }

    public void setTwoToOneLower(String twoToOneLower) {
        this.twoToOneLower = twoToOneLower;
    }

    public String getOneToTwoUpper() {
        return oneToTwoUpper;
    }

    public void setOneToTwoUpper(String oneToTwoUpper) {
        this.oneToTwoUpper = oneToTwoUpper;
    }

    public String getTwoToOneUpper() {
        return twoToOneUpper;
    }

    public void setTwoToOneUpper(String twoToOneUpper) {
        this.twoToOneUpper = twoToOneUpper;
    }

    public void addOneToTwo(String oneToTwo) {
        if (this.oneToTwo == null) {
            this.oneToTwo = "";
        }
        this.oneToTwo += oneToTwo + "\n";
    }

    public void addTwoToOne(String twoToOne) {
        if (this.twoToOne == null) {
            this.twoToOne = "";
        }
        this.twoToOne += twoToOne + "\n";
    }

    public void addOneToTwoLower(String oneToTwoLower) {
        if (this.oneToTwoLower == null) {
            this.oneToTwoLower = "";
        }
        this.oneToTwoLower += oneToTwoLower + "\n";
    }

    public void addTwoToOneLower(String twoToOneLower) {
        if (this.twoToOneLower == null) {
            this.twoToOneLower = "";
        }
        this.twoToOneLower += twoToOneLower + "\n";
    }

    public void addOneToTwoUpper(String oneToTwoUpper) {
        if (this.oneToTwoUpper == null) {
            this.oneToTwoUpper = "";
        }
        this.oneToTwoUpper += oneToTwoUpper + "\n";
    }

    public void addTwoToOneUpper(String twoToOneUpper) {
        if (this.twoToOneUpper == null) {
            this.twoToOneUpper = "";
        }
        this.twoToOneUpper += twoToOneUpper + "\n";
    }
}